<%-- ExMobi JSP文件，注释和取消快捷键统一为Ctrl+/ 多行注释为Ctrl+Shift+/ --%>
<%@ page language="java" import="java.util.*,sun.net.ftp.*,java.net.*"
 contentType="application/text; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/client/adapt.jsp"%>
<%@ include file="/client/adapt_extend.jsp"%>
<%@ include file="properties.jsp" %>
<%
	JSONObject json = new JSONObject();
    boolean ret = false;
    String msg = "";
    String path = aa.req.getParameter("path");
	path =(path.length()>0)?aa.common.deBase64(path):"/";
    
	FtpClient ftp = FtpClient.create();
	JSONArray list = new JSONArray();
	try{
		//连接ftp
		ftp.connect(new InetSocketAddress(_ftp_ip,_ftp_port));
		ftp.login(_ftp_userid, _ftp_pwd.toCharArray());
		ftp.setBinaryType();
		//获取文件列表
		InputStream is = ftp.list(path);
		InputStream is2 = ftp.nameList(path);
		Scanner scanner = new Scanner(is);
		Scanner scanner2 = new Scanner(is2);
		while(scanner.hasNext()){
			JSONObject item = new JSONObject();
			String line = scanner.nextLine();
			item.put("info", line);
			item.put("type", line.indexOf("<DIR>")!=-1?"DIR":"FILE");
			list.put(item);
		}
		int i=0;
		while(scanner2.hasNext()){
			String line = scanner2.nextLine();
			JSONObject item =list.getJSONObject(i);
			item.put("path", line);
			i++;
		}
		ret = true;
		msg = "访问完成";
	}catch(Exception e){
		  msg  = "FTP服务通讯失败！";
		  if(e instanceof java.io.FileNotFoundException){
			  msg = "文件不存在！";
		  }
		  System.out.println(msg);
		  System.out.println(e);
		  out.print(msg+" 错误信息："+e);
	}finally{
		ftp.close();
	}

	json.put("ret", ret);
	json.put("msg", msg);
	json.put("list",list);
	
	out.print(json.toString());
%>
